﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package ZLocalization {
    import flash.events.*;
    import flash.display.*;
    import flash.system.*;
    import flash.net.*;

    public class LocaleLoader {

        private static const FONT_MAPPER_DEFINITION:String = "FontMapper";

        protected var m_Loader:Loader;
        protected var m_urlLoader:URLLoader;
        protected var m_localizer:Localizer;
        protected var m_onComplete:Function;
        protected var m_isCompressed:Boolean;
        protected var m_loadFailed:Boolean;

        public function LocaleLoader(_arg1:String, _arg2:Function, _arg3:Boolean=false, _arg4:Boolean=true){
            this.m_onComplete = _arg2;
            if (_arg4){
                this.m_urlLoader = new URLLoader();
                this.m_isCompressed = _arg3;
                if (_arg3){
                    this.m_urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
                };
                this.m_urlLoader.addEventListener(Event.COMPLETE, this.onLoadXMLComplete);
                this.m_urlLoader.addEventListener(IOErrorEvent.IO_ERROR, this.onLoadXMLComplete);
                this.m_urlLoader.load(new URLRequest(_arg1));
            } else {
                this.m_Loader = new Loader();
                this.m_isCompressed = _arg3;
                if (_arg3){
                };
                this.m_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onLoadSWFComplete);
                this.m_Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.onLoadXMLComplete);
                this.m_Loader.load(new URLRequest(_arg1));
            };
        }
        public function get localizer():Localizer{
            return (this.m_localizer);
        }
        public function get loadFailed():Boolean{
            return (this.m_loadFailed);
        }
        protected function onLoadXMLComplete(_arg1:Event):void{
            this.m_urlLoader.removeEventListener(Event.COMPLETE, this.onLoadXMLComplete);
            this.m_urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, this.onLoadXMLComplete);
            if (!(_arg1 is IOErrorEvent)){
                if (this.m_isCompressed){
                    this.m_urlLoader.data.uncompress();
                };
                this.m_localizer = new LocalizerXML(new XML(this.m_urlLoader.data.toString()));
            } else {
                this.m_loadFailed = true;
            };
            if (this.m_onComplete != null){
                this.m_onComplete();
            };
            this.m_onComplete = null;
        }
        protected function onLoadSWFComplete(_arg1:Event):void{
            var _local2:LocalizerSWF;
            var _local3:ApplicationDomain;
            var _local4:Class;
            this.m_Loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, this.onLoadSWFComplete);
            this.m_Loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, this.onLoadSWFComplete);
            if (!(_arg1 is IOErrorEvent)){
                _local2 = new LocalizerSWF(_arg1.target.content);
                this.m_localizer = _local2;
                _local3 = this.m_Loader.contentLoaderInfo.applicationDomain;
                if (_local3.hasDefinition(FONT_MAPPER_DEFINITION)){
                    _local4 = (_local3.getDefinition(FONT_MAPPER_DEFINITION) as Class);
                    if (_local4){
                        this.localizer.m_fontMapper = new (_local4)();
                    };
                };
            } else {
                this.m_loadFailed = true;
            };
            if (this.m_onComplete != null){
                this.m_onComplete();
            };
            this.m_onComplete = null;
        }

    }
}//package ZLocalization 
